<?php

namespace App\Services;

use App\Models\CategoryModel;

class CategoryService extends BaseService {

    public function list($params) {
        $home = data_get($params, 'home', null);
        $page = data_get($params, 'page', 0);
        $limit = data_get($params, 'limit',20);

        $query = CategoryModel::query();

        $query->orderBy('id', 'desc');
        $res = $query->paginate($limit, CategoryModel::$columns, 'page', $page)->toArray();
        if ($home == 1){
            return $res;
        }else {
            return [
                'page' => $res['total'],
                'list' => $res['data']
            ];
        }
    }

    public function info($info_id){
        $res = CategoryModel::query()->where("id", $info_id)->first();
        return $res ? $res->toArray() : [];
    }

    public function delete($info_id){
        return CategoryModel::query()->where("id", $info_id)->delete();
    }
}